#!/usr/bin/env bash

red='\e[91m'
green='\e[92m'
yellow='\e[93m'
magenta='\e[95m'
cyan='\e[96m'
none='\e[0m'
blue='\033[34m'

# $@ 表示所有的参数列表。
# $# 表示传递给脚本的参数数量。
# $! 表示后台运行的最后一个进程的进程号。
# $0 表示脚本名
# 在 awk 中，$1 表示第一个字段，$2 表示第二个字段， $NF 表示最后一个字段

# sudo chmod 777 $0

# # Root
# [[ $(id -u) != 0 ]] && echo -e " 请使用 ${red}root ${none}用户运行 ${yellow}~(^_^) ${none}" && exit 1

get_passwd() {
  echo
  read -s -rp "请 输 入 开 机 密 码：" password
  echo
}

change_root(){
  if [[ $(id -u) != 0 ]];then
    if [ -z "$password" ]; then
      get_passwd
      export PASSWORD="$password"; sudo -v -S <<< "$PASSWORD"
    else
      sudo -v -S <<< "$PASSWORD"
    fi
  else
    sudo chmod 777 "$0"
  fi
}

# 获取系统架构
sys_str=$(uname -m)
# 修复系统软件标志位
software_repair_flag=''
# 文件标志位
file_flag=0
# 下载标志位
download_flag=''
# 获取普通用户
this_user=$(users | awk '{print $1}')
# 获取当前时间
timestamp=$(date +%Y-%m-%d_%H_%M_%S)
# 获取芯片，$1=$1用于去除字段前后的空格或制表符。
cpu_name=$(lscpu | grep "型号名称" | awk -F "：" '{print $2}' | awk '{$1=$1;print}')
# 获取根目录
#sys_root=$(lsblk -o NAME,MOUNTPOINT -P | grep -w / | awk -F" " '{print $1}' | awk -F"=" '{print $2}' | awk -F"\"" '{print $2}')
sys_root=$(lsblk -o NAME,MOUNTPOINT | grep -w "/" | awk '{sub("├─", "", $1); print $1}')
# 获取硬盘
my_disk=$(lsblk -d | grep disk | awk '{print $1}')
# 获取当前文件夹名NF取最后一个--如/home/leeyc/桌面，则桌面
# dir=$(pwd|awk -F "/" '{print $NF}')
os_version_small=$(cat /etc/kylin-build | grep -w "buildid" | awk -F" " '{print $2}')       # 获取buildid，比如2203-x86=31950，2303-x86=41998


# #确认当前系统是否为V10桌面版本
version_flag=$(cat /etc/kylin-build | awk '{print $2}' | awk 'NR==1')

#获取普通用户目录
home_path() {
  cd "/home/$this_user" || exit
}

desktop_path() {
  if [ -d "/home/$this_user/桌面" ]; then
    cd "/home/$this_user/桌面" || exit
  elif [ -d "/home/$this_user/desktop" ]; then
    cd "/home/$this_user/desktop" || exit
  fi
}

#暂停
get_pause() {
  SAVEDSTTY=$(stty -g)
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2>/dev/null
  stty -raw
  stty echo
  stty "$SAVEDSTTY"
}

#回到主菜单
return_menu(){
  echo
  echo -e "按任意键返回$yellow主菜单$none"
  get_pause
  echo
  menu
}

# print信息
show_print() {
  local options=("$@")
  for ((i=0; i<${#options[@]}; i++)); do
    echo
    echo -e "$blue ${options[$i]}$none"
  done
}

# menu显示菜单
show_menu() {
  echo
  echo -e "$green 0. $red 按 0 退出$none"
  local options=("$@")
  for ((i=0; i<${#options[@]}; i++)); do
    echo
    echo -e "$green $((i+1)). $red ${options[$i]}$none"
  done
  echo
  echo -e "温馨提示...如果你不想执行选项...按$magenta 0 $none或者 $magenta Ctrl + C $none即可退出"
  echo
}
# menu选择菜单
menu_selection() {
  read -r -p "$(echo -e "请选择菜单 [${green}0-$((${#menu_options[@]} - 1))$none]:")" choose
  if [[ -z $choose || ! $choose =~ ^[0-9]+$ || $choose -lt 0 || $choose -ge ${#menu_options[@]} ]]; then
    exit 1
  else
    selected_function="${menu_options[choose]}"
    eval "$selected_function"
  fi
}


# 1.系统信息
system_message() {
  head_print=(
    ".......................系统相关信息.........................."
  )
  options=(
    "查询系统信息并备份到桌面"
    "备份日志到桌面"
    "查看系统当前运行信息"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="system_info"
    ["2"]="backup_log"
    ["3"]="sys_operation_info"
  )
  menu_selection
}

## 1.1 获取系统基本信息
system_info() {
  change_root
  head_print=(
    ".......................请等待10秒左右.........................."
  )
  show_print "${head_print[@]}"
  version=$(sudo cat /etc/os-release | grep -w "VERSION" | awk -F"=" '{print $2}')              #系统版本
  version_build=$(sudo cat /etc/kylin-build | grep -w "Build" | awk -F" " '{print $2}')         #build号
  version_id=$(sudo cat /etc/kylin-build | grep -w "buildid:" | awk -F" " '{print $2}')         #版本id
  version_stone=$(sudo cat /etc/.kyinfo | grep -w "milestone" | awk -F"=" '{print $2}')         #版本号
  kylin_serial=$(sudo kylin_serial)                                                             #服务序列号
  kyregistration_key=$(sudo kylin_gen_register)                                                 #注册码
  if [ -f "/etc/.kyactivation" ]; then
    kyactivation_key=$(sudo cat /etc/.kyactivation 2>/dev/null)                                 #激活码
  else
    kyactivation_key=None
  fi                                                                     
  system_serial_number=$(sudo cat /sys/class/dmi/id/product_serial)                             #主机序列号
  main_bord=$(sudo dmidecode |grep -A9 "System Information" | awk '/UUID:/{print $2}')          #主板序列号
  #blk_serials=$(sudo lsblk -d -o NAME,SERIAL,TYPE -P | grep disk)                              #硬盘序列号
  blk_serials=$(sudo udevadm info --query=all --name=/dev/$my_disk | grep ID_SERIAL= | cut -d'=' -f2 | sed 's/ /-/g')
  phy_adapters=$(sudo ls /sys/class/net/ | grep -v "$(ls /sys/devices/virtual/net/)")           #网卡

  # os_version=$(head -n1 /etc/kylin-build |awk '{print $2}')                                   # 获取系统版本
  # cpu_name=Kirin990,2203version=20230310,os_version_small=40222
  echo -e "电脑cpu为: $cpu_name" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统版本为: $version" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统build版本为: $version_build" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统id号为: $version_id" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "操作系统版本为: $version_stone" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "服务序列号为：$kylin_serial" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "注册码: $kyregistration_key" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "激活码为: $kyactivation_key" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "主机序列号: $system_serial_number" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "主板序列号：$main_bord" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "硬盘序列号: $blk_serials" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "网卡为: $phy_adapters" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "网卡MAC地址:" | tee -a /home/"$this_user"/桌面/sys_info.txt
  for phy_adapter in $phy_adapters; do
    mac=$(cat /sys/class/net/"$phy_adapter"/address)
    echo "NAME=\"$phy_adapter\" MAC=\"$mac\"" | tee -a /home/"$this_user"/桌面/sys_info.txt
  done
  echo -e "根目录为：$sys_root" | tee -a /home/"$this_user"/桌面/sys_info.txt
  echo -e "\n\nwps序列号为：\n" | tee -a /home/"$this_user"/桌面/sys_info.txt  > /dev/null
  wps_content="$(tail -c 60 /opt/kingsoft/.auth/license2.dat | head -c 50 | tr -d '\00')"
  echo -e "wps序列号为:$wps_content" | tee -a /home/"$this_user"/桌面/sys_info.txt
  cat  /opt/kingsoft/wps-office/office6/cfgs/oem.ini | tee -a /home/"$this_user"/桌面/sys_info.txt  > /dev/null
  sudo cp  /opt/kingsoft/wps-office/office6/cfgs/oem.ini /home/"$this_user"/桌面/
  sudo chmod 777 /home/"$this_user"/桌面/sys_info.txt 
  sudo chmod 777 /home/"$this_user"/桌面/oem.ini
  echo -e "\n\n" | tee -a /home/"$this_user"/桌面/sys_info.txt  > /dev/null
  return_menu
}
## 1.2 备份log日志
backup_log(){
  change_root
  sudo tar -czvPf /home/"$this_user"/桌面/log_"$timestamp".tar.gz /var/log
  sudo chmod 777 /home/"$this_user"/桌面/log_"$timestamp".tar.gz
  echo -e "$magenta 找到log_$timestamp.tar.gz这个文件，备份到桌面了，从桌面拷出来发给我$none \n"
  return_menu
}
## 1.3 查看系统运行信息
sys_operation_info(){
  date | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "占用cpu最高的10个进程是:" | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  ps aux --sort=-%cpu|sed -n '1,11p' | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "占用mem最高的10个进程是:" | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  ps aux --sort=-%mem|sed -n '1,11p' | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "总体内存使用情况是:"  | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  free -h | tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo "中断情况是:"  | tee -a  /home/"$this_user"/桌面/stat_cpu_mem.txt
  tee -a /home/"$this_user"/桌面/stat_cpu_mem.txt <<< "$(</proc/interrupts)"
  echo  | tee -a  /home/"$this_user"/桌面/stat_cpu_mem.txt
  echo -e "$red 桌面有个stat_cpu_mem.txt文件，可打开查看信息"
  chmod 777 /home/"$this_user"/桌面/stat_cpu_mem.txt
  return_menu
}

# 2.部分系统bug修复
system_repair() {
  head_print=(
    "..........系统修复，有些修复是要在v10上用，v10sp1不可用，尽量询问之后再用......."
  )
  options=(
    "系统激活相关问题--如激活时不出现二维码等问题"
    "桌面任务栏、图标、黑屏、控制面板打不开、关机等相关问题"
    "桌面其他问题--密钥环、ll不生效"
    "系统软件问题--刻录软件、字体软件、exfat支持"
    "开发盘下处理--fsck与盘符挂载"
    "系统升级--需备份重要数据--没啥事儿不要乱升级，而且这个升级的时间，还不如重装了。"
    "可能有问题的功能"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="activation"
    ["2"]="sys_desk_bar"
    ["3"]="sys_desk_other"
    ["4"]="sys_soft_fix"
    ["5"]="desk_dev_fix"
    ["6"]="update_sys"
    ["7"]="mabe_bad_fuc"
  )
  menu_selection
}

## 2.1 系统激活相关
activation() {
  change_root
  head_print=(
    ".......................系统激活相关报错及相关功能.........................."
  )
  options=(
    "二维码灰色、无效序列号--下载对应系统版本的kyinfo文件"
    "修复激活时提示无法获取硬件信息错误码0017问题"
    "命令交互式激活操作系统"
    "查看及备份系统相关信息(版本、序列号、注册码、激活码)"
    "从V10升级系统到SP1后激活操作系统--要知道原来的序列号"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="activation_download"
    ["2"]="sudo rm -rf /etc/.kyhwid && sudo kylin_activation_check && return_menu"
    ["3"]="sudo kylin-system-verify && return_menu"
    ["4"]="system_info"
    ["5"]="sys_verify"
  )
  menu_selection
}

### 2.1.1 二维码灰色
activation_download() {
  head_print=(
    ".......................先看看电脑时间对不对，不对的话继续.........................."
  )
  options=(
    "安装V10-0710版本"
    "安装V10-1026版本"
    "安装V10-0710-2版本"
    "安装V10-1026-2版本"
    "安装V10-2107版本"
    "安装V10-2203版本"
    "安装V10SP1-2107版本"
    "安装V10SP1-2203版本"
    "安装V10SP1-2303版本"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="download_file act_v10_0710 act_zip"
    ["2"]="download_file act_v10_1026 act_zip"
    ["3"]="download_file act_v10_0710_2 act_zip"
    ["4"]="download_file act_v10_1026_2 act_zip"
    ["5"]="download_file act_v10_2107 act_zip"
    ["6"]="download_file act_v10_2203 act_zip"
    ["7"]="download_file act_v10sp1_2107 act_zip"
    ["8"]="download_file act_v10sp1_2203 act_zip"
    ["9"]="download_file act_v10sp1_2303 act_zip"
  )
  menu_selection
}

### 2.1.5 重新激活
sys_verify(){
  read -p "请输入原来的序列号之后回车：" new_number
  sudo sed -i "/^key=/s/key=[0-9]*/key=${new_number}/" /etc/.kyinfo
  echo -e "关闭所有激活相关的页面，然后重新我的电脑右键属性，重新点激活---二维码，联网状态大部分直接激活，不联网的重新扫码填入激活码"
  cat /etc/.kyinfo | grep "key="
  return_menu
}

## 2.2 桌面任务栏、图标、黑屏、控制面板打不开等相关问题
sys_desk_bar(){
  change_root
  head_print=(
    ".......................V10/V10SP1通用修复.........................."
    "......................部分是V10独有的，要注意......................"
  )
  options=(
    "V10/SP1--系统任务栏消失/右下角无小键盘及输入法"
    "V10/SP1--输入密码进不去桌面，跳回登录页面（原因之一：磁盘数据满，尝试清除部分数据）"
    "V10/SP1--垃圾软件清理"
    "V10/SP1--重装卸载残留的文件--注意重要文件要做备份，适用于安装或卸载软件导致系统出问题，且此时未清理软件垃圾"
    "V10/SP1--关机提示正在升级等"
    "V10/SP1--开机后桌面图标无显示/或显示正在启动caja只有任务栏/开机进tty1--黑屏(命令行),不进桌面"
    "V10--提示框：面板载入问题、任务栏显示有问题,执行完重启系统如果还报错执行下一个"
    "V10/SP1--控制面板打不开"
    "V10--关机卡麒麟软件四个字---特定情况出现：如安装身份鉴别等软件出现问题--lightdm报错缺pam_gnome_keyring.so\pam_kwallet.so\pam_kwallet.so错误"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="kylin_Taskbar"
    ["2"]="kylin_clean"
    ["3"]="kylin_clean"
    ["4"]="kylin_soft_reinstall"
    ["5"]="kylin_about_poweroff"
    ["6"]="kylin_about_caja"
    ["7"]="kylin_about_mate"
    ["8"]="kylin_about_control"
    ["9"]="cannot_poweroff"
  )
  menu_selection
}
### 2.2.1 系统任务栏消失/右下角无小键盘及输入法
kylin_Taskbar(){
  home_path
  sudo rm -rf .cache/ .config/ .Xauthority
  sudo systemctl restart lightdm
}

### 2.2.2 清理垃圾、输入密码进不去桌面，跳回登录页面
kylin_clean(){
  sudo apt clean
  sudo apt autoclean                                                #删/var/cache/apt/archives下deb文件
  sudo apt autoremove                                               #删不需要的依赖
  sudo dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo dpkg --purge #删软件残留配置--rc开头的文件
  sudo rm -rf /tmp/*                                                #删tmp缓存
}
### 2.2.4 重装卸载残留的文件--适用于安装或卸载软件导致系统出问题
kylin_soft_reinstall(){
  sudo dpkg -P upstart
  sudo dpkg -P firefox
  sudo apt install aptitude
  sudo dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo aptitude install -y
}

### 2.2.5 关机提示正在升级等
kylin_about_poweroff(){
  sudo rm /tmp/lock/kylin-update.lock
  sudo apt-get --reinstall install -y kylin-update-manager
  sudo rm /var/cache/apt/archives/lock
  sudo rm /var/lib/dpkg/lock-frontend
  sudo apt install -f
}
### 2.2.6 开机桌面图标无显示/开机进tty1---桌面caja有问题、重装caja和重装重置lightdm
kylin_about_caja(){
  sudo apt update
  sudo rm -rf .config/
  if [[ $version_flag == 'V10' ]];then
    sudo apt install caja --reinstall
  elif [[ $version_flag == 'V10-SP1' ]];then
    sudo apt install peony --reinstall
  fi
  sudo apt install lightdm --reinstall
  sudo dpkg-reconfigure lightdm
  sudo systemctl enable lightdm
}

### 2.2.7 面板载入问题
kylin_about_mate(){
  if [[ $version_flag == 'V10' ]];then
    sudo apt install mate-indicators --reinstall
  fi
}
### 2.2.8 控制面板打不开
kylin_about_control(){
  if [[ $version_flag == 'V10' ]];then
    sudo apt install kylin-control-center --reinstall
    sudo kylin-control-center
  elif [[ $version_flag == 'V10-SP1' ]];then
    sudo apt install ukui-control-center --reinstall
    ukui-control-center
  fi
}
 
### 2.2.9 关机卡麒麟软件四个字
cannot_poweroff(){
  sudo sed -i  "/keyring/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm
  sudo sed -i  "/kwallet/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm
  sudo sed -i  "/keyring/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm-greeter
  sudo sed -i  "/kwallet/s/^\(.*\)$/#&/g" /etc/pam.d/lightdm-greeter
}


## 2.3 系统其他问题修复
sys_desk_other(){
  change_root
  head_print=(
    ".......................V10/V10SP1通用修复.........................."
    "......................部分是V10或SP1独有的，要注意......................"
  )
  options=(
    "V10/SP1--桌面密钥环消除"
    "V10/SP1--ll查看命令不生效--误删.bashrc和.bash_profile文件"
    "V10--尝试增加exfat硬盘支持"
    "V10SP1--关闭执行控制--脚本不能执行--安全中心可手动设置"
    "V10SP1--关闭网络控制--部分应用网络不可用--安全中心可手动设置"
    "V10SP1--关闭应用来源检查--安装软件时的检查--安全中心可手动设置"
    "V10SP1--老版本如2107激活的系统，服务到期提示已过期--V10不要选，此处未作判断"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="seahorse_kylin"
    ["2"]="no_bashrc"
    ["3"]="sudo apt install exfat-fuse exfat-utils"
    ["4"]="sudo setstatus -f exectl off -p"
    ["5"]="sudo setstatus -f netctl off -p"
    ["6"]="sudo setsignstatus off"
    ["7"]="sudo apt install ukui-control-center --reinstall"
  )
  menu_selection
}

### 2.3.1 桌面密钥环消除
seahorse_kylin(){
  sudo apt install seahorse -y
  echo -e "$red 三秒后在打开的界面右键点密码下的key，删除即可$none"
  sleep 3
  sudo seahorse
}
### 2.3.2 ll不生效
no_bashrc(){
  home_path
  sudo cp /etc/skel/.bashrc ./
  sudo chmod 644 .bashrc
  sudo touch .bash_profile
  echo -e "if [ -f ~/.bashrc ]; then\n\t. ~/.bashrc\nfi" | sudo tee .bash_profile
}

## 2.4 系统软件修复
sys_soft_fix(){
  change_root
  head_print=(
    "..................系统主要涉及两个软件.........................."
    "....................1.刻录软件2.字体......................"
  )
  options=(
    "V10SP1-2203--刻录软件除990-2203外的续刻问题--此处未判断990"
    "V10SP1-2303--刻录软件超103字符无法刻录问题"
    "V10/SP1---字体相关问题"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="download_file kelu_xuke deb_zip"
    ["2"]="download_file kelu_zifu_2303 deb_zip"
    ["3"]="fuc_fonts"
  )
  menu_selection
}

## 2.5 开发盘下修复
desk_dev_fix(){
  change_root
  head_print=(
    "..................开发盘下fsck修复或挂载盘.........................."、
  )
  options=(
    "盘无法挂载，需修复"
    "挂载开发盘"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="fsck_disk"
    ["2"]="mount_disk"
  )
  menu_selection
}
### 2.5.1 修复fsck
fsck_disk(){
  DEV_UUID=$(blkid | grep "TYPE=\"ext4\"" | awk '{print $2}' | cut -d '"' -f 2)
  if [ -z "$DEV_UUID" ]; then
    echo "无法找到开发盘"
    exit 1
  fi
  # 根据UUID执行fsck命令
  echo "正在对分区 $DEV_UUID 进行fsck修复..."
  fsck -y /dev/disk/by-uuid/$DEV_UUID
}
### 2.5.2 挂载开发盘
mount_disk(){
  sudo mkdir -p /disk01
  sudo chmod -R 777 /disk01
  sudo mount /dev/nvme0n1p2 /disk01
  echo -e "打开文件系统下disk01文件夹查看"
  return_menu
}

## 2.6 更新系统
update_sys(){
  head_print=(
    ".....................系统升级-备份重要数据--没啥事儿不要乱升级...................."
    "....................................没测试过，自测.............................."
    "..........................用cat /etc/.kyinfo查看系统版本........................"
    "...................................一步一步升级................................."
    "之后查看链接，下载升级包https://www.kylinos.cn/support/update.html?impact=&system_type_id=&update_type_id=3&query_key="
  )
  options=(
    "V10-2020年的0710等升级到21年的2101"
    "V10-2021年的2101等升级到21年的2107"
    "V10SP1-还没写"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="download_file sys_update_v10_0710 deb"
    ["2"]="download_file sys_update_v10_2101 deb"
  )
  menu_selection
}
## 2.7 可能非好用的功能
mabe_bad_fuc(){
  change_root
  head_print=(
    "..................开发盘下fsck修复或挂载盘.........................."、
  )
  options=(
    "触摸板滑动方向改为windows一致"
    "校准时间--若有ntp服务"
    "解锁uos#TODU"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="sudo synclient VertScrollDelta=-30"
    ["2"]="ntpdate time.windows.com"
    ["3"]="unblock_uos"
  )
  menu_selection
}

unblock_uos(){
  chattr -i /var/lib/deepin/developer-mode/enabled
  rm -rf /var/lib/deepin/developer-mode/enabled
}

# 3.源与商店更新及修复
software_repair() {
  head_print=(
    ".......................修复系统源、软件商店相关报错.........................."
  )
  options=(
    "修复系统软件源---如商店里软件较少"
    "更新源时提示GPG错误"
    "更新软件源时，提示等待报头一直为0、软件源无法加锁"
    "安装软件提示失败"
    "软件商店报错---如打开商店报0001-0005等代码、dbus服务异常--重装软件商店"
    "软件商店报错---如打开商店报0001-0005等代码、dbus服务异常--不重装软件商店"
    "软件商店打不开---V10-0710等安装新版本商店后打不开--装老版本商店且后续不要升级"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="systemUpdate"
    ["2"]="softcenter_repair soft_GPG"
    ["3"]="softcenter_repair soft_lock"
    ["4"]="softcenter_repair soft_install_fail"
    ["5"]="softcenter_repair soft_wrong_code_soft"
    ["6"]="softcenter_repair soft_wrong_code"
    ["7"]="softcenter_repair 0710_cantopen"    
  )
  menu_selection
}

## 3.1系统源更新
systemUpdate() {
  head_print=(
    "...........原则上更新管理器会在开机几分钟内，顶多一小时自行向公司的源发请求更新源地址。............."
    "....................因最近系统升级，最好只用1，下面的暂时大多数失效了，还没去看....................."
  )
  options=(
    "解锁源、从麒麟官网更新源(序列号对应系统版本一致)"
    "备份现有源"
    "还原刚备份的源"
    "修复V10并锁源"
    "修复V10-sp1-2303并锁源"
    "修复V10-sp1-hwe-2303并锁源"
    "修复V10-sp1-990-2203并锁源"
    "修复V10-sp1-990-2303-update1并锁源"
    "修复V10-sp1-9006c-2203并锁源"
    "修复V10-sp1-9006c-2303-update1并锁源"
    "修复V10-sp1-2403并锁源"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  change_root
  file="/etc/apt/sources.list"
  if lsattr "$file" | grep -q "i"; then
    sudo chattr -i $file
  fi
  read -r -p "$(echo -e "$cyan 请选择0-10: $none ")" _opt
  #/usr/share/kylin-software-properties/template/default-source
  echo
  if [[ -z $_opt ]]; then
      error
    else
      case $_opt in
      0)
        menu
        ;;
      1)
        sudo chattr -i $file
        sudo kylin-source-update
        return_menu
        ;;
      2)
        sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
        ;;
      3)
        sudo cp /etc/apt/sources.list.bak /etc/apt/sources.list
        ;;
      4)
        sudo tee /etc/apt/sources.list << EOF
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0 main restricted universe multiverse
deb http://archive2.kylinos.cn/DEB/KYLIN_DEB V10 main all
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0-fixs main
EOF
sudo chattr +i $file
        ;;
      5)
        sudo tee /etc/apt/sources.list << EOF
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main restricted universe multiverse
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-2303-updates main universe restricted multiverse 
deb http://archive2.kylinos.cn/DEB/KYLIN_DEB V10-SP1 main all
EOF
sudo chattr +i $file
        ;;
      6)
        sudo tee /etc/apt/sources.list << EOF
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main restricted universe multiverse
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-2303-updates main universe restricted multiverse 
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/dists/10.1-2303-hwe-updates main restricted universe multiverse
deb http://archive2.kylinos.cn/DEB/KYLIN_DEB V10-SP1 main all
EOF
sudo chattr +i $file
        ;;
      7)
        sudo tee /etc/apt/sources.list << EOF
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-wayland-2203-updates main universe restricted multiverse 
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-kirin990-feature main 
deb https://archive2.kylinos.cn/deb/kylin/production/PART-10_1-kirin9a0/custom/partner/10_1-kirin9a0 default all 
EOF
        sudo chattr +i $file
        ;;
      8)
        sudo tee /etc/apt/sources.list << EOF
deb http://archive2.kylinos.cn/deb/kylin/production/PART-10_1-kirin9a0/custom/partner/10_1-kirin9a0 default all
deb http://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-kirin990-2303-feature main
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1 main restricted universe multiverse
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-wayland-2303-updates main restricted universe multiverse
EOF
        sudo chattr +i $file
        ;;
      9)
        sudo tee /etc/apt/sources.list << EOF
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-wayland-2203-updates main universe restricted multiverse 
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-kirin9006C-feature main
deb https://archive2.kylinos.cn/deb/kylin/production/PART-10_1-kirin9a0/custom/partner/10_1-kirin9a0 default all
EOF
        sudo chattr +i $file
        ;;
      10)
        sudo tee /etc/apt/sources.list << EOF
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1 main universe restricted multiverse
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-wayland-2303-updates main universe restricted multiverse
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-kirin9006C-2303-feature main
deb https://archive2.kylinos.cn/deb/kylin/production/PART-10_1-kirin9a0/custom/partner/10_1-kirin9a0 default all
EOF
sudo chattr +i $file
        ;;
      11)
        sudo tee /etc/apt/sources.list << EOF
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1 main universe restricted multiverse
deb https://archive.kylinos.cn/kylin/KYLIN-ALL/ 10.1-2403-updates main universe restricted multiverse
deb http://archive2.kylinos.cn/DEB/KYLIN_DEB V10-SP1 main all
EOF
sudo chattr +i $file
        ;;
      esac
    fi
  sudo apt update
}

#3.2 源、商店错误处理
softcenter_repair() {
  change_root
  local software_repair_flag=$1
  if [ "$software_repair_flag" == 'soft_GPG' ]; then
    #源GPG错误
    sudo mv /var/lib/apt/lists /var/lib/apt/list_"$timestamp"
    sudo mkdir -p /var/lib/apt/lists/partial
    sudo apt clean
    sudo apt update
    return_menu
  elif [ "$software_repair_flag" == 'soft_lock' ]; then
    #源报头为0
    sudo rm -rf /var/lib/apt/lists/*
    sudo apt update
    return_menu
  elif [ "$software_repair_flag" == 'soft_install_fail' ]; then
    #软件安装失败
    sudo apt install --fix-broken
    sudo apt install -f
    sudo apt-get update --fix-missing
    return_menu
  elif [ "$software_repair_flag" == 'soft_wrong_code_soft' ]; then
    #软件商店报错--重装软件商店
    sudo apt update
    sudo apt install --fix-broken
    sudo apt install -f
    sudo apt install -y kylin-software-center --reinstall
    sudo rm /var/lib/dpkg/updates/*
    sudo rm -rf /var/lib/apt/lists/*
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/cache/apt/archives/lock
    sudo dpkg --configure -a
    sudo apt update
    return_menu
  elif [ "$software_repair_flag" == 'soft_wrong_code' ]; then
    #软件商店报错--不重装软件商店
    sudo apt update
    sudo apt install --fix-broken
    sudo apt install -f
    sudo rm /var/lib/dpkg/updates/*
    sudo rm -rf /var/lib/apt/lists/*
    sudo rm /var/lib/dpkg/lock
    sudo rm /var/lib/dpkg/lock-frontend
    sudo rm /var/cache/apt/archives/lock
    sudo dpkg --configure -a
    sudo apt update
    return_menu
  elif [ "$software_repair_flag" == '0710_cantopen' ]; then
    #mips老版本如0710安装最新商店报错
    # sudo apt-cache show kylin-software-center
    sudo apt  install  kylin-software-center=4.5.54kord
    sudo apt update
    return_menu
  fi
}


#4.软件相关
software(){
  head_print=(
    ".......................我的电脑右键属性--FT2000属于ARM、3A4000属于mips.........................."
    ".......................1.notepad--gitee地址：https://gitee.com/cxasm/notepad--......................."
    ".......................2.落雪六音音源下载地址http://www.downxia.com/downinfo/448468.html......................."
  )
  options=(
    "社交软件相关--微信、QQ、腾讯会议、蓝信"
    "远程软件相关--向日葵、Todesk"
    "影音下载相关--哔哩哔哩、yesplaymusic、落雪、阿里小白羊"
    "字体编辑相关--字体安装、金山wps清理缓存、金山wps安装个人版、安装notepad--x86:2.20,arm:3.0,loong:2.0"
    "网络浏览器相关--360等浏览器下载、flash插件下载、老版本easyconnect"
    "解包重新打包--比如安装后没图标的，以及从统信下载的包"
    "安装编译环境，如qt等---暂部分有问题"
    "下载制作ISO镜像的工具"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="fuc_social"
    ["2"]="fuc_remote"
    ["3"]="fuc_movieMusicDown"
    ["4"]="fuc_edit"
    ["5"]="fun_net_browser"
    ["6"]="fuc_change_deb"
    ["7"]="about_code"
    ["8"]="download_file mk_iso deb"
    ["99"]="fuc_crossover"
  )
  menu_selection
}

# 4.1 社交软件相关
fuc_social() {
  change_root
  head_print=(
    ".................微信qq腾讯会议相关问题处理...................."
    ".................1.微信安装--20241224........................."
    ".................2.微信所有问题处理，脚本已自行判断，但网络有限制导致的无法扫码的情况需找网络的人.........."
    ".................3.新版QQ应该是只支持SP1全架构，V10部分支持，可测试....................................."
    ".................4.QQ花屏问题处理............................."
    ".................5.腾讯会议应该是只支持SP1架构................."
    ".................6.下载蓝信arm版.............................."
    ".................7.关闭IPV6.................................."
  )
  options=(
    "微信安装"
    "微信问题处理"
    "QQ安装"
    "QQ花屏处理"
    "腾讯会议下载"
    "蓝信下载"
    "关闭IPV6"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  read -r -p "$(echo -e "$magenta 请选择数字: $none")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      sudo apt update
      if [[ $version_flag == 'V10' ]];then
        sudo apt install -y kylin-activation libkylin-activation zlib1g
        download_file 'wechat_beta' 'deb'
      else
        sudo apt install -y wechat
      fi
      ;;
    2)
      sudo killall -9 weixin || sudo killall -9 wechat
      if [[ $version_flag == 'V10' ]];then
        if [ "$sys_str" == "aarch64" ]; then
          download_file 'wechat_beta' 'deb'
        elif [ "$sys_str" == "mips64" ]; then
          sudo apt install -y kylin-activation libkylin-activation zlib1g
          dpkg --get-selections wechat-beta
          if [ $? -eq 0 ]; then
            sudo dpkg -r wechat-beta
            sudo dpkg -P wechat-beta
            download_file 'wechat_beta' 'deb'
          fi
          if ! grep -q "--disable-gpu" /usr/share/applications/wechat.desktop; then
            sudo cp /usr/share/applications/wechat.desktop /usr/share/applications/wechat.desktop_"$timestamp"
            sudo sed -i 's/Exec=wechat %U/Exec=wechat  --disable-gpu  %U/' /usr/share/applications/wechat.desktop
            sudo sed -i 's/Exec=wechat %U/Exec=wechat  --disable-gpu  %U/' /home/"$this_user"/桌面/wechat.desktop
          fi
        fi
        sudo tee /etc/apt/sources.list << EOF
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0 main restricted universe multiverse
deb http://archive2.kylinos.cn/DEB/KYLIN_DEB V10-SP1 main all
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 10.0-fixs main
EOF
        sudo apt update && sudo apt install -y kylin-activation libkylin-activation
        echo -e "请关闭微信并重新打开微信。$none \n"
      fi
      return_menu
      ;;
    3)
      download_file 'tencent_linuxqq' 'deb'
      ;;
    4)
      download_file 'tencent_linuxqq_fix' 'deb'
      ;;
    5)
      download_file 'tencent_metting' 'deb'
      ;;
    6)
      download_file 'lanxin' 'deb'
      ;;
    7)
      if ! grep -q 'GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"' /etc/default/grub; then
          sudo sed -i '$ a\GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"' /etc/default/grub
      fi
      if ! grep -q 'GRUB_CMDLINE_LINUX="ipv6.disable=1"' /etc/default/grub; then
          sudo sed -i '$ a\GRUB_CMDLINE_LINUX="ipv6.disable=1"' /etc/default/grub
      fi
      sudo update-grub
      echo -e "执行完了，请重启下系统$none \n"
      ;;
    esac
  fi
}

#4.2 远程相关下载
fuc_remote() {
  xhost +
  head_print=(
    ".................注意有时这些软件第一次打开有时连不上，需要右下角退出重新打开一遍................."
    ".................在左下角开始菜单--所有程序里打开向日葵或todesk................."
  )
  options=(
    "公司源中安装向日葵--首选"
    "公司源中安装todesk--首选"
    "安装Todesk的x86和arm版---此软件无mips"
    "老版本离线安装向日葵10.0版---V10MIPS常用，arm有问题也可用这个，最新版本尽量不用"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="sudo apt install sunloginclient"
    ["2"]="sudo apt install todesk"
    ["3"]="download_file todesk deb"
    ["4"]="download_file sunlogin deb"
  )
  menu_selection
  change_root
  sudo apt install -f
  head_print=(
    ".................在左下角开始菜单--所有程序里打开向日葵或todesk................."
  )
  return_menu
}

# 4.99 crossover试用
fuc_crossover(){
  change_root
  home_path
  cd ".cxoffice/" || exit
  change_root
  sudo find . -name ".eval" -exec rm -f {} \;
  sudo rm -f {}
  return_menu
}

# 4.3 影音下载相关
fuc_movieMusicDown() {
  change_root
  head_print=(
    ".................影音下载相关问题处理................."
    ".................1.下载哔哩哔哩................."
    ".................2.下载网易云音乐第三方................."
    ".................3.下载落雪音乐................."
    ".................4.下载阿里云盘................."
  )
  options=(
    "下载哔哩哔哩"
    "下载网易云音乐第三方"
    "下载落雪音乐"
    "下载阿里云盘"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="download_file bilibilidl deb"
    ["2"]="download_file yesplaymusic deb"
    ["3"]="download_file lxmusic deb"
    ["4"]="download_file aliyunpan deb"
  )
  menu_selection
}

#4.4 编辑软件安装
fuc_edit() {
  change_root
  head_print=(
    ".................安装字体，可百度搜ttf文件或在Windows中拷贝................."
    ".......使用方法:双击ttf文件右上角有安装，适用于单个ttf安装及客户自行安装字体。.........."
  )
  options=(
    "在公司源中安装字体管理器"
    "批量安装字体脚本--点完看桌面"
    "清除wps缓存"
    "备份wps激活信息"
    "安装免费wps个人版"
    "安装nodpad--"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  read -r -p "$(echo -e "$magenta 请选择数字: $none")" _opt
  echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
    0)
      menu
      ;;
    1)
      sudo apt install -y gnome-font-viewer
      ;;
    2)
      fonts_shell
      ;;
    3)
      quickstartoffice stop
      home_path
      sudo rm -rf .config/Kingsoft
      sudo rm -rf .local/share/Kingsoft
      quickstartoffice start
      return_menu
      ;;
    4)
      sudo cp  /opt/kingsoft/wps-office/office6/cfgs/oem.ini /home/"$this_user"/桌面/
      sudo chmod 777 /home/"$this_user"/桌面/oem.ini
      return_menu
      ;;
    5)
      dpkg_wps=$(dpkg -l | grep wps | awk '{print $2}')
      sudo dpkg --force-all --purge $dpkg_wps
      download_file 'wps_personal' 'deb'
      ;;
    6)
      download_file 'notepad' 'deb'
      ;;
    esac
  fi
  return_menu
}

fonts_shell() {
  change_root
  desktop_path
  pwd
  sudo mkdir newfonts
  sudo mkdir -p /usr/share/fonts/newfonts
  sudo chmod -R 777 ./newfonts/
  echo
  echo -e "$magenta 请将ttf字体文件拷到newfonts文件夹中再按任意键继续进行操作:"
  return_menu
  echo
  sudo chmod -R 777 ./newfonts/
  sudo cp ./newfonts/* /usr/share/fonts/newfonts/
  sudo chmod -R 777 /usr/share/fonts/newfonts/
  sudo fc-cache /usr/share/fonts/newfonts/
  ls /usr/share/fonts/newfonts/
  echo -e "$red 应该可以用了，重新打开wps，fc相关组件未安装的需要重启下电脑。$none \n"
}

# 4.5 浏览器相关
fun_net_browser(){
  head_print=(
    ".......................网络浏览器相关.........................."
  )
  options=(
    "尝试给浏览器装flash插件"
    "下载360浏览器"
    "老V10-easyconnect下载，新版已换atrust，需找天融信公司要"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="sudo apt install -y kylin-flash-plugin"
    ["2"]="sudo apt install browser360-cn-stable"
    ["3"]="download_file easyconnect deb"
  )
  menu_selection
}
#4.8 解包再打包
fuc_change_deb(){
  #TODU切换普通用户
  if [[ $(id -u) == 0 ]]; then
    # get_passwd
    # sudo -u $this_user -S <<< "$password"
    echo -e "请用普通用户执行"
    exit;
  fi
  echo -e "先保证这个deb包与你右键打开终端处于同一文件夹下，比如你在桌面右键打开的终端，此deb就该在桌面"
  echo -e "注意deb的包名应与原来一致，比如在uos微信是com.tencent.weixin，在kylin是weixin，就要把package改为weixin。"
  read -r -p "$(echo -e "$magenta 请输入需解包的deb名(建议提前改成比较简单的名:before，不用加deb): $none")" before_name
  read -r -p "$(echo -e "$magenta 请输入解包的文件夹名(如mynewdeb): $none")" mynewdeb_dir
  read -r -p "$(echo -e "$magenta 请输入最终生成的deb包名:after，不用加deb: $none")" after_name
  dpkg-deb -R $before_name.deb $mynewdeb_dir
  cd $mynewdeb_dir
  mkdir -p ./usr/share/
  sed -i '/^Depends:/ s/deepin-elf-verify *(>= *[0-9][^)]*),\{0,1\}//' ./DEBIAN/control
  sed -i 's/,[[:space:]]*$//' ./DEBIAN/control
  find . -type d -name "applications" -not -path "./usr/*" -exec cp -rp {} ./usr/share/ \;
  find . -type d -name "icons" -not -path "./usr/*" -exec cp -rp {} ./usr/share/ \;
  cd ..
  echo -e "如果还有其他要改的，请自行打开control等文件并修改，之后按$yellow任意键$none继续"
  get_pause
  dpkg-deb --build $mynewdeb_dir $after_name.deb
}

#4.9 编译相关
about_code(){
  head_print=(
    ".......................代码编译相关-arm-v10sp1-2303.........................."
    ".......................需要在上面的选项3-1中先更新源.........................."
  )
  options=(
    "安装vscode1.82.2--最新版地址：https://code.visualstudio.com/Download#，需要特定网络"
    "安装qtcreator-可商店直接搜索"
    "安装git"
    "安装make\cmake"
    "安装g++、gcc、cpp"
    "安装qt工具和库--暂有问题"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="download_file vscode deb"
    ["2"]="sudo apt install qtcreator qtcreator-data"
    ["3"]="sudo apt install git"
    ["4"]="sudo apt install make cmake"
    ["5"]="sudo apt install g++ gcc cpp"
    ["6"]="sudo apt install qtbase5-dev qt5-qmake qtbase5-dev-tools libqt5printsupport5 libqt5xmlpatterns5-dev"
  )
  menu_selection
}

#5.打印机驱动安装

install_cups(){
  change_root
  head_print=(
    ".......................此处安装什么驱动需咨询麒麟员工.........................."
    "...........驱动去麒麟官网查https://eco.kylinos.cn/zoology/commercial.html?system_class=1..........."
    "...........佳能基本要去佳能官网查https://www.canon.com.cn/supports/download/sims/search/index..........."
  )
  options=(
    "安装惠普3.16.3"
    "安装惠普3.22.x或最新版"
    "安装佳能2900、3000--arm+mips"
    "奔图打印机驱动--一般去https://www.pantum.cn/support/download/driver/自行下载#TUDOrar未处理"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="sudo apt install hp-printer-hplip-3.16.3"
    ["2"]="sudo apt install hplip"
    ["3"]="download_file canon2900 deb"
    ["4"]="download_file bentu7105dn deb_zip"
  )
  menu_selection
}

# 6.其他功能
other_fuc() {
  head_print=(
    "..........其他功能，如查看网速，查找文件、查找安装包......."
    "..........上传文件到ftp、母盘打包镜像......."
  )
  options=(
    "查看实时网速"
    "查找文件或安装包或服务"
    "上传文件到FTP"
    "解包镜像并生成新镜像"
    "增加rc.local"
    "杀进程，如输入xunlei\weixin\weichat这样的"
    "查看硬盘速度，一般固态硬盘会百兆或以上"
    "统信开启开发者"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="net_speed"
    ["2"]="find_files"
    ["3"]="up_to_ftp"
    ["4"]="mkiso"
    ["5"]="add_rc_local"
    ["6"]="kill_process"
    ["7"]="dd if=/dev/zero of=~/diskspeed bs=1M count=1024 oflag=sync && sync && rm ~/diskspeed"
    ["8"]="uos_root"
  )
  menu_selection
}

## 6.1 实时网速
net_speed() {
  echo -e " In ------ Out"
  read -r -p "$(echo -e "请输入测试时长（秒）：")" duration
  start_time=$(date +%s)
  while [[ $(date +%s) -lt $((start_time + duration)) ]]; do
    OLD_IN=$(awk '{print $2}' /proc/net/dev | awk 'NR==4{print $1}')
    OLD_OUT=$(awk '{print $10}' /proc/net/dev | awk 'NR==4{print $1}')
    sleep 1
    NEW_IN=$(awk '{print $2}' /proc/net/dev | awk 'NR==4{print $1}')
    NEW_OUT=$(awk '{print $10}' /proc/net/dev | awk 'NR==4{print $1}')
    IN=$(printf "%.1f%s" "$(( ("$NEW_IN" - "$OLD_IN") / 1024 ))" "KB/s")
    OUT=$(printf "%.1f%s" "$(( ("$NEW_OUT" - "$OLD_OUT") / 1024 ))" "KB/s")
    echo "$IN $OUT"
  done
  return_menu
}

#6.2 文件查找
find_files() {
  head_print=(
    ".......................文件、安装包、服务查找.........................."
    "..........查找的文件名或路径名保存在本目录下的find开头的txt文件中......."
  )
  options=(
    "按名称查找文件(区分大小写)"
    "按名称查找文件(不区分大小写)"
    "按文件内容查找(只在home和data目录下查找--原则上用户数据都在这俩目录)"
    "按文件内容查找(自定义目录)"
    "查找源里的软件包"
    "查找本机所有安装的软件包"
    "查找本机是否安装软件包--如输入linuxqq看有没有安装qq"
    "查找本机服务名--如输入ssh看有ssh服务名"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="findname file_case"
    ["2"]="findname file_nocase"
    ["3"]="findname file_content"
    ["4"]="findname file_own_content"
    ["5"]="findname soft_source"
    ["6"]="findname soft_local_all"
    ["7"]="findname soft_local"
    ["8"]="findname service_local"
  )
  menu_selection
}

findname() {
  change_root
  local file_flag=$1
  if [ "$file_flag" == 'file_case' ]; then
    read -r -p "$(echo -e "请输入要查找的文件名:")" name
    sudo find /home/ -name "$name*" -print | tee find"$name".txt
    return_menu
  elif [ "$file_flag" == 'file_nocase' ]; then
    read -r -p "$(echo -e "请输入要查找的文件名:")" name
    sudo find /home/ -iname "$name*" -print | tee find"$name".txt
    return_menu
  elif [ "$file_flag" == 'file_content' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" content
    sudo grep -rl "$content" /home /data | tee find"$content".txt
    return_menu
  elif [ "$file_flag" == 'file_own_content' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" content
    read -r -p "$(echo -e "请输入要查找的位置，多个位置用空格隔开:")" loc
    sudo grep -rl "$content" "$loc" | tee find"$content".txt
    return_menu
  elif [ "$file_flag" == 'soft_source' ]; then
    read -r -p "$(echo -e "请输入要查找的内容:")" soft_source
    sudo apt search "$soft_source"
    return_menu
  elif [ "$file_flag" == 'soft_local_all' ]; then
    echo -e "安装的软件包输出到文件中"
    sudo dpkg --get-selections | tee installsoftware.txt
    return_menu
  elif [ "$file_flag" == 'soft_local' ]; then
    read -r -p "$(echo -e "请输入要查找的安装包名:")" soft_local
    sudo dpkg --get-selections | grep "$soft_local"
    return_menu
  elif [ "$file_flag" == 'service_local' ]; then
    read -r -p "$(echo -e "请输入要查找的服务名:")" service_local
    systemctl  list-units --type=service --full --all | grep "$service_local"
    return_menu
  fi
}

#6.3.1 上传到ftp
up_to_ftp(){
  head_print=(
    "..............本脚本作用：查找数据盘和/home/文件夹下某时间段修改过的文件并打包................."
    "..............注意：比如2021年创建的，但是2022年修改过的不算.................................."
    "..............注意：数据盘应保有足够大的空间执行打包操作，空间不够大的不适合这个脚本。..........."
    "..............备份的数据多则备份时间长，备份中不要按回车，请耐心等待............................"
  )
  options=(
    "第一次执行请直接按1打包不成功重试"
    "打包成功，但是因为种种原因没能上传成功请按2"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
	read -r -p "$(echo -e "${red} 确定上面的都读过了，请选择数字: ${none}")" _opt
	echo
  if [[ -z $_opt ]]; then
    error
  else
    case $_opt in
      1)
        pack_file
        rename_file
        remote_file
        ;;
      2)
        get_file_name
        remote_file
        ;;
    esac
  fi
}

#6.3.2 打包文件
pack_file(){
  read -r -p "$(echo -e "请输入要打包文件的起始时间如 2022-01-01 :")" starttime
  read -r -p "$(echo -e "请输入要打包文件的结束时间如 2023-01-01 :")" endtime
	find  /data/ /home/ ! -name '.*' -a ! -regex '.*/\.[^/]*/.*' -type f -print0 -newermt  "$starttime" ! -newermt "$endtime" | xargs -0 tar -czPf /data/test.tar.gz
  echo
	echo -e "已经打包好了，在/data/下，目前叫test.tar.gz"
}
#6.3.3 重命名文件
rename_file(){
  head_print=(
    ".........接下来我们将给你即将打包的文件取个名字，比如：张三................."
    ".........建议取自己的名字，但不要跟其他人的名称重复,尤其不要取111,222之类的名......."
    ".........切换好你的输入法..........."
    ""
  )
  show_print "${head_print[@]}"
	read -r -p "$(echo -e "请输入你的文件名:${none}")" name
	echo
	echo -e "这个文件将被改为：${red}${name}.tar.gz ${none}，按任意键继续进行操作:"
  sleep 10
	echo
  return_menu
	echo
	mv /data/test.tar.gz /data/"$name".tar.gz
	chmod 755 /data/"$name".tar.gz
  echo
	echo -e "已经重命名好了，此文件名为：${red}${name}.tar.gz${none}"
}

#6.3.4 推到远程ftp服务器
remote_file(){
  head_print=(
    ".........现在即将把这个文件传到ftp服务器上去................."
    ".........比如ftp目录为文件夹:upload/2021......."
    ".........为了安全此脚本内不内置服务器密码，需要自己输入一下..........."
    ".........上传的文件大则上传时间长，请耐心等待........."
    ".........了解后按任意键继续进行操作:........."
  )
  show_print "${head_print[@]}"
  get_pause
	echo
  read -r -p "$(echo -e "请输入服务器IP地址如 192.168.210.5 ")" addr
	echo
  read -r -p "$(echo -e "请输入服务器端地址如 /ftpdata/upload/2021/ ")" addr_home
  echo
	echo -e "请输入服务器密码:"
	echo
  #scp /data/$name.tar.gz  root@192.168.210.5:/ftpdata/upload/2021/
	scp /data/"$name".tar.gz  root"$addr":"$addr_home"
	echo
	echo -e " 已经上传好了，请打开左下角开始菜单，找到FileZilla这个FTP软件查看"
	echo
	rm -rif /data/"$name".tar.gz
  echo
}

### 6.3.5 获取文件名
get_file_name(){
	echo
	echo -e "${cyan} 比如说你的数据盘下的文件为：${red}张三.tar.gz${none}${cyan}，则直接输入：${red}张三${none}"
	echo
	read -r -p "$(echo -e " 请输入文件名：")" name
	echo
	echo -e " 要上传的文件名为：${red}${name}.tar.gz ${none}，确定则按任意键继续进行操作:"
	echo
  return_menu
	echo
}

## 6.4 制作镜像 
mkiso(){
  change_root
  head_print=(
    ".........现在即将制作iso镜像，制作分三步................."
    "...............第一步，先选1解压缩ISO镜像......................"
    ".........第二步，如果你看起来退出了当前脚本，则已进入squashfs模式，执行sudo  bash  /tmp/run.sh..........."
    ".........第三步，选择2进行iso镜像的封装........."
  )
  options=(
    "选1解压缩ISO镜像"
    "选2进行iso镜像的封装"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="unsquashfs_iso"
    ["2"]="mksquashfs_iso"
  )
  menu_selection
}

### 6.4.1 解压缩镜像
unsquashfs_iso(){
  if [ -d "/opt/livecd" ]; then
    rm -rf /opt/livecd/*
  else
    mkdir -p /opt/mnt /opt/livecd /opt/tool
  fi
  read -p "请 输 入 ISO所在绝对路径(此路径下只能有一个iso镜像):" absolute_path
  mount "$absolute_path"/*.iso /opt/mnt/
  cp -rp /opt/mnt/. /opt/livecd/ 
  umount /opt/mnt/
  cd /opt/livecd/casper/
  unsquashfs filesystem.squashfs

  read -p "请 输 入 安 装 包 地 址：" deb_path
  if [ -z "$deb_path" ]; then
    exit 1
  fi
  cp "$deb_path"/*.deb /opt/livecd/casper/squashfs-root/tmp
  echo "$red 如果你看起来退出了当前脚本，则已进入squashfs模式，执行sudo  bash  /tmp/run.sh" 
  echo "然后exit，再重新执行此脚本，选择2 $none" 
  sudo tee /opt/livecd/casper/squashfs-root/tmp/run.sh << EOF
sudo mount -t proc none /proc
sudo mount -t sysfs none /sys
sudo mount -t devpts none /dev/pts
sudo dpkg -i /tmp/*.deb
sudo rm -rf /tmp/* 
sudo umount /proc 
sudo umount /sys 
sudo umount /dev/pts
exit
EOF
  chroot squashfs-root
}
### 6.4.2
mksquashfs_iso(){
  
  cd /opt/livecd/casper
  rm filesystem.squashfs
  mksquashfs squashfs-root filesystem.squashfs -comp xz
  printf $(du -sx --block-size 1 squashfs-root |cut -f1) >filesystem.size 
  chattr -R -i squashfs-root

  rm -r squashfs-root
  cd /opt/livecd/
  rm md5sum.txt
  find -type f -print0 | xargs -0 md5sum|grep -v isolinux/boot.cat |tee md5sum.txt
  cd /opt/livecd/
  if [ "$sys_str" == "x86_64" ]; then
    mkisofs -J -r -V "Kylin-Desktop-V10-x86" -cache-inodes -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -o /opt/Kylin-V10-desktop-x86.iso . 
  elif [ "$sys_str" == "aarch64" ]; then
    genisoimage -e boot/grub/efi.img -no-emul-boot -T -J -R -c boot.catalog -hide boot.catalog -V "Kylin-V10-desktop-arm" -o /opt/Kylin-V10-desktop-arm.iso .
  elif [ "$sys_str" == "mips64" ]; then
    mkisofs -b casper/initrd.img -no-emul-boot -T -J -R -c boot.catalog -hide boot.catalog -V "Kylin-V10-desktop-mips64el" -o /opt/Kylin-V10-desktop-mips64el.iso .
  else
    echo "暂不支持" && exit 1
  fi
}

## 6.5 增加rc.local
add_rc_local(){
  change_root
  echo -e "\n[Install]\nWantedBy=multi-user.target\n" | sudo tee -a /lib/systemd/system/rc-local.service
  sudo touch /etc/rc.local && chmod 755 /etc/rc.local
  echo -e "#!/bin/bash\n" | sudo tee  /etc/rc.local
  sudo systemctl daemon-reload
  sudo systemctl start rc-local.service
  sudo systemctl enable rc-local.service
  echo -e "接下来可以自己编辑vim /etc/rc.local添加开机启动项了。"
}
## 6.6 杀进程
kill_process(){
  read -r -p "$(echo -e "$magenta 请输入想杀到的进程(如xunlei): $none")" proc_name
  ps -ef | awk -v pn="$proc_name" '$0 ~ pn {print $2}' | xargs kill
}

uos_root(){
  # [ -d /var/lib/deepin/developer-mode ] || mkdir -pv /var/lib/deepin/developer-mode
  # chattr -i /var/lib/deepin/developer-mode/enabled
  # echo -n -E 1 > /var/lib/deepin/developer-mode/enabled
  download_file uos_root_file deb
}

#7.服务器相关
about_server(){
  change_root
  head_print=(
    ".......................本脚本作用：服务器相关.........................."
  )
  options=(
    "尝试修复yum makecache报错，如error: rpmdb: xxx failed"
    "内网源挂载"
    "FTP服务端--VSFTP安装--安装后使用FillZilla访问"
    "SAMBA安装-只一个账户"
    "vnc-server安装"
    "mysql数据备份"
    "做bond"
    "openssh改版本号"
    "防火墙开关"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="rpm_repair"
    ["2"]="net_source"
    ["3"]="ftp_install"
    ["4"]="smb_install"
    ["5"]="vnc_install"
    ["6"]="mysql_backup"
    ["7"]="bond_install"
    ["8"]="openssh_change"
    ["9"]="firewalld_open_close"
  )
  menu_selection
}
## 7.1 rpm修复
rpm_repair(){
  sudo rm -f /var/lib/rpm/__db*
  sudo db_verify /var/lib/rpm/Packages
  sudo rpm --rebuilddb
}

## 7.2 内网源挂载
net_source(){
  read -s -rp "插入U盘的话请按1并手动输入挂载地址，插入光盘则可直接回车：" opt

  case $opt in
    1)
      read -s -rp "请输入挂载地址：" mounted
      MOUNTPOINT=$mounted
      ;;
    *)
      if grep -qs '/dev/sr0' /proc/mounts; then
        MOUNTPOINT=$(grep '/dev/sr0' /proc/mounts | awk '{print $2}')
      else
        mkdir -p /media/root/Kylin-server
        mount /dev/sr0 /media/root/Kylin-server
        MOUNTPOINT=/media/root/Kylin-server
      fi
      ;;
  esac
  mkdir -p /data/Kylin-server
  echo -e "开始复制"
  rsync -a --info=progress2 $MOUNTPOINT/* /data/Kylin-server
  sed -i -e '/\[ks10-adv-os\]/,/enabled = 1/ s|^\(baseurl =.*\)|#\1\nbaseurl=file:///data/Kylin-server|' \
       -e '/\[ks10-adv-updates\]/,/enabled = 1/ s/enabled = 1/enabled = 0/' /etc/yum.repos.d/kylin_x86_64.repo
	yum clean all
  yum makecache
  echo -e "应该是挂载上了"
}

# 7.3 ftp安装
ftp_install(){
  change_root
  head_print=(
    ".......................本脚本作用：安装配置ftp.........................."
  )
  options=(
    "安装及配置VSFTP--安装后配置有问题的也可通过此修改"
    "批量添加用户"
  )
  show_print "${head_print[@]}"
  show_menu "${options[@]}"
  menu_options=(
    ["0"]="return_menu"
    ["1"]="vsftp_install"
    ["2"]="add_ftpuser"
  )
  menu_selection
}

vsftp_install(){
  if vsftpd -v >/dev/null 2>&1; then
      echo "vsftpd 已安装。"
  else
      yum install -y vsftpd >/dev/null 2>&1
      if [ $? -eq 0 ]; then
          echo "vsftpd 成功安装."
          systemctl start vsftpd >/dev/null 2>&1
          systemctl enable vsftpd >/dev/null 2>&1
          echo "vsftpd 服务已启动，并已开机自启。"
      else
          echo "vsftpd 安装失败，看看源是不是有问题"
          exit 1
      fi
  fi
  firewall-cmd --permanent --zone=public --add-service=ftp
  firewall-cmd --reload

  # 配置vsftpd
  read -p "是否配置vsftp配置文件： [yes/no] " answer
  if [[ "$answer" =~ ^[Yy][Ee][Ss]$ ]]; then
    config=/etc/vsftpd/vsftpd.conf
    cp $config $config_$timestamp

    sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' $config
    #sed -i 's/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/g' $config
    sed -i 's/#chown_uploads=YES/chown_uploads=YES/g' $config
    sed -i 's/#async_abor_enable=YES/async_abor_enable=YES/g' $config
    sed -i 's/#ascii_upload_enable=YES/ascii_upload_enable=YES/g' $config
    sed -i 's/#ascii_download_enable=YES/ascii_download_enable=YES/g' $config
    sed -i 's/#ftpd_banner/ftpd_banner/g' $config
    sed -i 's/#chroot_local_user=YES/chroot_local_user=NO/g' $config
    sed -i 's/#chroot_list_enable=YES/chroot_list_enable=YES/g' $config
    sed -i 's/#chroot_list_file/chroot_list_file/g' $config

    # 定义要添加的配置项数组
    config_items=(
        "pasv_min_port=4500"
        "pasv_max_port=5000"
        "allow_writeable_chroot=YES"
    )

    # 遍历数组，分别判断每个配置项是否已经存在
    for item in "${config_items[@]}"; do
        if grep -q "$item" "$config"; then
            echo "配置项 '$item' 已存在，无需添加。"
        else
cat >> "$config" << EOF
$item
EOF
            echo "配置项 '$item' 添加成功。"
        fi
    done
  fi

  # 重启vsftpd服务
  systemctl restart vsftpd >/dev/null 2>&1
  echo "vsftpd 服务已重启."
  add_ftpuser
}

add_ftpuser(){
  ftpConfig=/etc/vsftpd
  echo "如下配置完最终效果就是：用户yd01的文件存放在/data/ftp/yd01: "
  read -p "请输入ftp文件存放的根目录，比如/data/ftp：" ftpPath
  if [ ! -d "$ftpPath" ]; then
    echo "ftp目录不存在，创建对应目录$ftpPath: "
    mkdir -p "$ftpPath"
    chmod 755 "$ftpPath"
  fi

  while true; do
    read -p "请输入ftp用户名，直到输入done结束配置：" user_name
    if [[ "$user_name" == "done" ]]; then
        break
    fi
    if id "$user_name" >/dev/null 2>&1; then
      echo "用户名已存在，请重新输入。"
    else
      echo "添加 vsftp 账号： $user_name"
      useradd -s /bin/bash -d "$ftpPath/$user_name" $user_name
      chown -R $user_name:$user_name "$ftpPath/$user_name"
      chmod -R 700 "$ftpPath/$user_name"
      while true; do
        echo "请输入vsftp账号密码，注意密码要有复杂度，要大于8字符且三个类型："
        echo "比如：xz123@qq.com，得复杂一些，密码不可见，盲输入"
        passwd $user_name
        if [ $? -eq 0 ]; then
          echo "密码设置成功。"
          break
        else
          echo "密码设置失败，请重新输入。"
        fi
      done

      touch $ftpConfig/chroot_list
      echo "$user_name" >> $ftpConfig/chroot_list
    fi
  done

  systemctl restart vsftpd >/dev/null 2>&1
}


## 7.4 smb安装
smb_install(){
  if smbd --version >/dev/null 2>&1; then
    echo "samba 已安装。"
  else
    yum install -y samba >/dev/null 2>&1
    if [ $? -eq 0 ]; then
      echo "samba 成功安装."
    else
      echo "samba 安装失败，看看源是不是有问题"
      exit 1
    fi
  fi
  cp /etc/samba/smb.conf /etc/samba/smb.conf.bak_$timestamp

  read -p "请输入samba文件存放的位置：" smb_dir
  mkdir -p $smb_dir
  read -p "请输入samba用户：" smb_user
  useradd $smb_user
  echo -e "samba123@qq.com\nsamba123@qq.com" | smbpasswd -a $smb_user
  echo -e "samba默认密码是：samba123@qq.com，需要的话password $smb_user 自行修改密码"

  cat << EOF > /etc/samba/smb.conf
[global]
   workgroup = WORKGROUP
   server string = Samba Server %v
   netbios name = samba_server
   security = user
   map to guest = bad user
   dns proxy = no

[samba_share]
   comment = Samba Share
   path = $smb_dir
   browsable = yes
   guest ok = no
   read only = no
   valid users = $smb_user
EOF
  
  firewall-cmd --permanent --zone=public --add-service=samba
  firewall-cmd --reload
  systemctl start smb >/dev/null 2>&1
  systemctl start nmb >/dev/null 2>&1
  systemctl enable smb >/dev/null 2>&1
  systemctl enable nmb >/dev/null 2>&1
  echo -e "Windows请访问\\ip，举例\\192.168.59.168，Linux请访问smb://ip，如smb://192.168.59.168"
  get_pause
}


## 7.5 vncserver安装
vnc_install(){
  yum install tigervnc-server -y
  cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
  vncuser='root'
  read -s -rp "请 输 入 用 户 名，默 认 root,用户提前在图形化建好：" vncuser
  if [ "$vncuser" == "root" ]; then
    sed -i 's|/home/<USER>|/root|g' /etc/systemd/system/vncserver@:1.service
    sed -i "s|<USER>|$vncuser|g" /etc/systemd/system/vncserver@:1.service
  else
      sed -i "s|<USER>|$vncuser|g" /etc/systemd/system/vncserver@:1.service
  fi
  echo "接下来输入vnc密码，此密码8位且最好复杂点，比如Q!W@e3as这样。"
  vncpasswd
  systemctl daemon-reload
  systemctl start vncserver@:1.service
  systemctl enable vncserver@:1.service
}

# 7.6 mysql备份
mysql_backup(){
  dump_dir='/data/backup/mysql'
  mkdir -p  "$dump_dir/$timestamp"
  read -p "请输入数据库用户名,如root等："  database_usr_name
  read -s -p "请输入数据库密码，密码不可见，盲输入："  database_passwd
  read -p "请输入连接的数据库名："  database_name
  mysqldump -h127.0.0.1 -u"$database_usr_name" -p"$database_passwd" --databases "$database_name" > $dump_dir/$timestamp/mysql_$timestamp.sql
}

# 7.7 做bond
bond_install(){
  device_names=$(nmcli device | awk '$2 == "ethernet" {print $1}')
  echo "可用的网络设备："
  for name in $device_names; do
    echo "$name"
  done
  systemctl restart NetworkManager
	systemctl enable NetworkManager
	read -p "请输入你要做的bond名称，如bond0：" bond_devices

	nmcli connection add type bond con-name $bond_devices ifname $bond_devices bond.options "mode=active-backup,miimon=100" ipv4.method disabled ipv6.method disabled autoconnect yes
	
	read -p "请输入要绑定的设备号（上面列出来的，请输入第一个）：" bond1_devices
	read -p "请输入要绑定的设备号（上面列出来的，请输入第二个）：" bond2_devices
	mv /etc/sysconfig/network-scripts/ifcfg-$bond1_devices /etc/sysconfig/network-scripts/ifcfg-$bond1_devices.$timestamp
	mv /etc/sysconfig/network-scripts/ifcfg-$bond2_devices /etc/sysconfig/network-scripts/ifcfg-$bond2_devices.$timestamp
	nmcli connection add type ethernet ifname $bond1_devices master $bond_devices autoconnect yes
	nmcli connection add type ethernet ifname $bond2_devices master $bond_devices autoconnect yes

	read -p "请业务口ipv4地址：如x.x.11.x/27: " ipv4_num
	read -p "请业务口ipv4地址：如x.x.11.x/27: " ipv4_gateway
	nmcli connection modify $bond_devices ipv4.method manual ipv4.addresses $ipv4_num  ipv4.gateway $ipv4_gateway
	nmcli connection up bond-slave-$bond1_devices
	nmcli connection up bond-slave-$bond2_devices
	nmcli connection up $bond_devices
}

# 7.8 openssh改版本号
openssh_change(){
  my_variable=$(strings /usr/sbin/sshd | grep OpenSSH | head -n 1)
  read -p "请输入你想改的openssh的版本号比如OpenSSH_9.7p1: " ssh_new
  sed -i "s/$my_variable/$ssh_new/g" /usr/sbin/sshd
  sed -i "s/$my_variable/$ssh_new/g" /usr/bin/ssh
  systemctl  restart  sshd
  ssh -V
}

#7.9 开关防火墙
detect_firewall() {
    if command -v firewall-cmd &> /dev/null; then
        echo "firewalld"
    elif command -v iptables &> /dev/null; then
        echo "iptables"
    else
        echo "none"
    fi
}
manage_port() {
    local action=$1
    local port=$2
    local firewall=$3
    case $firewall in
        "firewalld")
            if [ "$action" == "open" ]; then
                firewall-cmd --zone=public --add-port=${port}/tcp --permanent
            elif [ "$action" == "close" ]; then
                firewall-cmd --zone=public --remove-port=${port}/tcp --permanent
            fi
            firewall-cmd --reload
            ;;
        "iptables")
            if [ "$action" == "open" ]; then
                iptables -A INPUT -p tcp --dport $port -j ACCEPT
            elif [ "$action" == "close" ]; then
                iptables -D INPUT -p tcp --dport $port -j ACCEPT
            fi
            service iptables save
            service iptables restart
            ;;
        *)
            echo "不支持的防火墙."
            exit 1
            ;;
    esac
}
firewalld_open_close() {
    firewall=$(detect_firewall)
    if [ "$firewall" == "none" ]; then
        echo "未检测到支持的防火墙软件。"
        exit 1
    fi

    echo "检测到的防火墙软件是: $firewall"

    read -p "请输入要操作的端口号: " port
    read -p "请输入操作类型，输入：open或close): " action

    if [[ "$action" != "open" && "$action" != "close" ]]; then
        echo "无效的操作类型。请输入 'open' 或 'close'。"
        exit 1
    fi

    manage_port $action $port $firewall
    echo "端口操作完成并刷新了防火墙规则。"
}

# 下载地址获取
get_download_link() {
  local download_flag="$1"

  case $download_flag in
    "act_v10_0710")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_0710.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_0710.zip"
      fi
      ;;
    "act_v10_0710_2")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_0710_2.zip"
      fi
      ;;
    "act_v10_1026")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_1026_2.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_arm_1026.zip"
      fi
      ;;
    "act_v10_1026_2")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/old/act_V10_mips_1026_2.zip"
      fi
      ;;
    "act_v10_2107")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_mips_2107.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_arm_2107.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2107/act_v10_x86_2107.zip"
      fi
      ;;
    "act_v10_2203")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_V10_mips_2203.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_V10_arm_2203.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10/2203/act_v10_x86_2203.zip"
      fi
      ;;
    "act_v10sp1_2107")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_mips_2107.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_arm_2107.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2107/act_V10SP1_x86_2107.zip"
      fi
      ;;
    "act_v10sp1_2203")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_mips_2203.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_arm_2203.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_x86_2203.zip"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2203/act_V10SP1_loongarch_2203.zip"
      fi
      ;;
    "act_v10sp1_2303")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_mips_2303.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_arm_2303.zip"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_x86_2303.zip"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Activation/V10SP1/2303/act_V10SP1_loongarch_2303.zip"
      fi
      ;;
    "kelu_xuke")
      case $sys_str in
        "mips64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_mips.zip"
          ;;
        "aarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_arm.zip"
          ;;
        "x86_64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_x86.zip"
          ;;
        "loongarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/xuke-2203/xuke_loongarch64.zip"
          ;;
      esac
      ;;
    "kelu_zifu_2303")
      case $sys_str in
        "mips64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_mips.zip"
          ;;
        "aarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_arm.zip"
          ;;
        "x86_64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_x86.zip"
          ;;
        "loongarch64")
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/kylin-burner/keluzifu-2303/keluzifu_2303_loongarch.zip"
          ;;
      esac
      ;;
    "vscode")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/code/VScode/vscode_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/code/VScode/vscode_arm64.deb"
      fi
      ;;
    "wps_personal")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_arm64.deb?t=1713517548&k=76df4b259943bc907e9fc26f152fd800"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_amd64.deb?t=1713517623&k=556c0e86005afcd6390bc7b1df0bfe37"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_loongarch64.deb?t=1713517677&k=32ca31da653110df7a218c74b41b8cb9"
      elif [ "$sys_str" == "mips64" ]; then
        echo "https://wps-linux-personal.wpscdn.cn/wps/download/ep/Linux2019/11719/wps-office_11.1.0.11719_mips64el.deb?t=1713517643&k=0ac19eea9b1f467ee5a9f6f91157565f"
      fi
      ;;
    "canon2900")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/cups/Canon/captdriver_mips64el.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/cups/Canon/captdriver_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "bentu7105dn")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10%2Bsv_mips64el.rar"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10_amd64_deb.zip"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10%2Bsv_arm64.rar"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://drivers.pantum.cn/userfiles/files/download/drive/%E5%9B%BD%E4%BA%A7/pantum_7_4_170-1%2Bkl10_loongarch64_deb.zip"
      fi
      ;;
    "todesk")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://newdl.todesk.com/linux/todesk-v4.3.1.0-arm64.deb"
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://newdl.todesk.com/linux/todesk-v4.3.1.0-amd64.deb"
      fi
      ;;
    "sunlogin")
      if [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_mips.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        if [ "$cpu_name" == "Kirin990" ]; then
          if [ "$os_version_small" == "40222" ]; then
            echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunlogin-990-2203.zip"
            #TUDO
          else
            echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunloginclient_11.0.0.36662_arm64_kirin990_1228.deb"
          fi
        elif [ "$cpu_name" == "HUAWEI Kirin 9006C" ]; then
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/11.x/sunloginclient_11.0.0.36662_arm64_kirin9a0_20220221.deb"
      else
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_arm64.deb"
      fi
      elif [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/sunlogin/10.x/sunloginclient-10.0.2.24779_kylin_x86_64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "wechat_beta")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://archive2.kylinos.cn/DEB/KYLIN_DEB/pool/main/deb/wechat/wechat_4.0.1.7-1_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        if [[ $version_flag == 'V10' ]];then
          echo "https://archive2.kylinos.cn/DEB/KYLIN_DEB/pool/all/wechat-beta_1.0.0.240_arm64.deb"
        else
          echo "https://archive2.kylinos.cn/DEB/KYLIN_DEB/pool/main/deb/wechat/wechat_4.0.1.7-1_arm64.deb"
        fi
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://archive2.kylinos.cn/DEB/KYLIN_DEB/pool/main/deb/wechat/wechat_4.0.1.7-1_loongarch64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        if [[ $version_flag == 'V10' ]];then
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Tencent/Wechat/Mips/wechat_2.0.0_mips64el.deb"
        else
          echo "https://archive2.kylinos.cn/DEB/KYLIN_DEB/pool/main/deb/wechat-beta/wechat-beta_1.0.0.241-3_mips64el.deb"
        fi
      fi
      ;;
    "tencent_linuxqq")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://dldir1.qq.com/qqfile/qq/QQNT/cbb0e5d9/linuxqq_3.2.9-24815_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://dldir1.qq.com/qqfile/qq/QQNT/cbb0e5d9/linuxqq_3.2.9-24815_arm64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://dldir1.qq.com/qqfile/qq/QQNT/cbb0e5d9/linuxqq_3.2.9-24815_loongarch64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        if [[ $version_flag == 'V10' ]];then
          echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Tencent/QQ/Mips/linuxqq_2.0.0-b4_mips64el.deb"
        else
          echo "https://dldir1.qq.com/qqfile/qq/QQNT/cbb0e5d9/linuxqq_3.2.9-24815_mips64el.deb"
        fi
      fi
      ;;
    "tencent_linuxqq_fix")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/Tencent/QQ/fix/gf-arise-linux-graphics-driver-dri_25.00.19_aarch64.deb"
      fi
      ;;
    "tencent_metting")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://updatecdn.meeting.qq.com/cos/fcdc2a010a25561a4d23e168b677b493/TencentMeeting_0300000000_3.19.1.400_x86_64_default.publish.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://updatecdn.meeting.qq.com/cos/206c30da5545dba38a29ccbc752dec94/TencentMeeting_0300000000_3.19.1.401_arm64_default.publish.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://updatecdn.meeting.qq.com/cos/23810840e7e8bb38536b2a59ae811343/TencentMeeting_0300000000_3.19.1.401_loongarch64_default.publish.deb"
      fi
      ;;
    "aliyunpan")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/aliyun/aliyun_amd.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/aliyun/aliyun_arm.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "notepad")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/notepad/notepad_x86.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/notepad/notepad_arm64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/notepad/notepad_loong.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "yesplaymusic")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/music/yesplaymusic/yesplaymusic_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/music/yesplaymusic/yesplaymusic_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "lxmusic")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/music/lxmusic/lx-music_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/music/lxmusic/lx-music_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "bilibilidl")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/movie/bilibili/bilibili_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/movie/bilibili/bilibili_arm64.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/movie/bilibili/bilibili_loong64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "easyconnect")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/easyconnect/EasyConnect_arm64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "sys_update_v10_0710")
      if [ "$sys_str" == "x86_64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/v10-200710-210122/pool/kylin-update-patch_10-ori-20210209-200710-210122_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/v10-200710-210122/pool/kylin-update-patch_10-ori-20210209-200710-210122_arm64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/v10-200710-210122/pool/kylin-update-patch_10-ori-20210209-200710-210122_mips64el.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "sys_update_v10_2101")
      if [ "$sys_str" == "x86_64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/V10_2101-2107/pool/kylin-update-desktop_10-ori-2101-2107_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/V10_2101-2107/pool/kylin-update-desktop_10-ori-2101-2107_arm64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        echo "http://archive.kylinos.cn/kylin-tmp-upgrade/V10_2101-2107/pool/kylin-update-desktop_10-ori-2101-2107_mips64el.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "mk_iso")
      if [ "$sys_str" == "x86_64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-5_amd64.deb"
      elif [ "$sys_str" == "aarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-5_arm64.deb"
      elif [ "$sys_str" == "mips64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-1_mips64el.deb"
      elif [ "$sys_str" == "loongarch64" ]; then
        echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/MKISO/kylin-iso-master_1.0.1-1_loongarch64.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "lanxin")
      if [ "$sys_str" == "aarch64" ]; then
        echo "https://package.lanxin.cn/client/linux/lanxin-aarch64-kylinv10sp1_Official_7.36.1026.108372.deb"
      else
        echo "暂不支持" && exit 1
      fi
      ;;
    "uos_root_file")
      echo "https://kylin-1253703239.cos.ap-nanjing.myqcloud.com/za/open-root.deb"
      ;;
    *)
      echo "暂不支持" && exit 1
      ;;
  esac
}

# 下载方法
download_file() {
  change_root
  local download_flag=$1
  local down_format_flag=$2
  downzip_tmp="/tmp/$download_flag/"
  if [[ $down_format_flag == "act_zip" || $down_format_flag == "deb_zip" ]]; then
    download_tmp_file="/tmp/$download_flag/$download_flag.zip"
  elif [[ $down_format_flag == "deb" ]]; then
    download_tmp_file="/tmp/$download_flag/$download_flag.deb"
  elif [[ $down_format_flag == "deb_rar" ]]; then
    download_tmp_file="/tmp/$download_flag/$download_flag.deb"
  fi
  mkdir -p "$downzip_tmp"

  download_link=$(get_download_link "$download_flag")

  echo "$download_flag"
  echo "$down_format_flag"
  echo "$download_tmp_file"
  echo "$download_link"

  if ! wget --no-check-certificate -O "$download_tmp_file" "$download_link"; then
    echo -e "$red 下载文件失败..$none" && exit 1
  fi
  cd "$downzip_tmp" || exit
  
  if [[ $down_format_flag == "act_zip" || $down_format_flag == "deb_zip" ]]; then
    unzip -o "$download_flag".zip
    if [[ $down_format_flag == "deb_zip" ]]; then
      sudo chmod 777 -- ./*.deb
      sudo dpkg -i -- ./*.deb
      sudo dpkg -i -- ./*.deb
    elif [[ $down_format_flag == "act_zip" ]]; then
      sudo cp "$downzip_tmp"/.kyinfo "$downzip_tmp"/LICENSE /etc/
      echo -e "$red 应该是修改完了，关闭之前的激活页面，重新打开激活页面激活一下吧。$none \n"
    fi
  elif [[ $down_format_flag == "deb" ]]; then
    sudo chmod 777 -- ./*.deb
    sudo dpkg -i -- ./*.deb
  fi

  if [ "$download_flag" == "dfonts" ]; then
    echo -e "$red 应该是下载并安装成功了，右键ttf文件在字体查看器中打开，右上角有安装按钮。$none \n"
  fi
  return_menu
}


#程序入口
menu() {
  while :; do
    head_print=(
      ".......................系统环境异常修复.........................."
      "..........我的电脑右键属性--FT2000属于ARM、3A4000属于mips........"
      ".....注意很多修复相关的是要在v10上用，有的是v10sp1可用，尽量询问之后再用....."
    )
    options=(
      "查看系统信息--系统基本信息、实时系统信息、备份系统日志"
      "修复系统问题--激活问题、桌面无状态栏、图标等"
      "软件源、软件商店相关---修复软件源、软件少、软件无法安装、软件商店报错等问题"
      "软件相关--微信、远程、字体、金山等"
      "打印机相关"
      "其他功能"
      "服务器相关"
    )
    show_print "${head_print[@]}"
    show_menu "${options[@]}"
    menu_options=(
      ["0"]="return_menu"
      ["1"]="system_message"
      ["2"]="system_repair"
      ["3"]="software_repair"
      ["4"]="software"
      ["5"]="install_cups"
      ["6"]="other_fuc"
      ["7"]="about_server"
    )
    menu_selection
  done
}
args=$1
[ -z "$1" ] && args="menu"
case $args in
menu)
  menu
  ;;
esac
